package com.test.platform

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import com.test.platform.ui.screen.ProjectListScreen
import com.test.platform.ui.screen.DeveloperInfoScreen
import com.test.platform.ui.screen.PublishInfoScreen
import com.test.platform.ui.screen.XTSReportScreen
import com.test.platform.ui.theme.TestPlatformTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            TestPlatformTheme {
                MainScreen()
            }
        }
    }
}

@Composable
fun MainScreen() {
    var selectedTab by remember { mutableStateOf(0) }
    
    val navigationItems = listOf(
        NavigationItem(
            title = "项目",
            icon = R.drawable.ic_project_outline,
            selectedIcon = R.drawable.ic_project_filled
        ),
        NavigationItem(
            title = "开发",
            icon = R.drawable.ic_developer_outline,
            selectedIcon = R.drawable.ic_developer_filled
        ),
        NavigationItem(
            title = "发布",
            icon = R.drawable.ic_publish_outline,
            selectedIcon = R.drawable.ic_publish_filled
        ),
        NavigationItem(
            title = "报告",
            icon = R.drawable.ic_report_outline,
            selectedIcon = R.drawable.ic_report_filled
        )
    )

    Scaffold(
        modifier = Modifier.fillMaxSize(),
        bottomBar = {
            NavigationBar {
                navigationItems.forEachIndexed { index, item ->
                    NavigationBarItem(
                        icon = {
                            Icon(
                                painter = painterResource(
                                    if (selectedTab == index) item.selectedIcon else item.icon
                                ),
                                contentDescription = item.title
                            )
                        },
                        label = { Text(item.title) },
                        selected = selectedTab == index,
                        onClick = { selectedTab = index }
                    )
                }
            }
        }
    ) { innerPadding ->
        when (selectedTab) {
            0 -> ProjectListScreen(modifier = Modifier.padding(innerPadding))
            1 -> DeveloperInfoScreen(modifier = Modifier.padding(innerPadding))
            2 -> PublishInfoScreen(modifier = Modifier.padding(innerPadding))
            3 -> XTSReportScreen(modifier = Modifier.padding(innerPadding))
        }
    }
}

data class NavigationItem(
    val title: String,
    val icon: Int,
    val selectedIcon: Int
)